import request from "./request";

const MOCK = false;

export function getTimeRange() {
  if (!MOCK) return request("get", "/api/fudan/volunteer/time/range");
  return Promise.resolve({
    data: {
      code: 0,
      content: {
        readingTime: "2022/04/26 14:30:00",
        startAnswerTime: "2022/04/26 14:30:20",
        endAnswerTime: "2022/04/26 14:31:40",
      },
    },
  });
}

// export function getWXUserInfo() {
//   if (!MOCK) return request("get", "/api/fudan/wx/login");
//   return Promise.resolve({
//     data: {
//       code: 0,
//     },
//   });
// }

// eslint-disable-next-line no-unused-vars
export function getQuestion(token, page = 1, limit = 20) {
  if (!MOCK) {
    return request(
      "get",
      `/api/fudan/volunteer/exam/list?page=${page}&limit=${limit}`,
      {},
      token
    );
  }
  return Promise.resolve({
    data: {
      code: 0,
      page: {
        totalCount: 3,
        list: [
          {
            examType: 0,
            examTitle: "测试单选问题",
            examOptions: ["好的", "不好的"],
            examId: "1",
          },
          {
            examType: 1,
            examTitle: "测试多选问题",
            examOptions: ["好的", "不好的"],
            examId: "2",
          },
          {
            examType: 2,
            examTitle: "测试文本问题",
            examId: "3",
          },
        ],
      },
    },
  });
}

export function getTeamInfo(page = 1, limit = 50) {
  if (!MOCK) {
    return request(
      "get",
      `/api/fudan/volunteer/team/list?page=${page}&limit=${limit}`
    );
  }
  return Promise.resolve({
    data: {
      code: 0,
    },
  });
}

export function saveUserInfo({ username, mobile, userId, teamId }) {
  if (!MOCK) {
    return request("post", "/api/fudan/volunteer/appuser/save", {
      username,
      mobile,
      userId,
      teamId,
    });
  }
  return Promise.resolve({
    data: {
      code: 0,
    },
  });
}

export function saveAnswer({ userId, examAnswer, examId }, token) {
  if (!MOCK) {
    return request(
      "post",
      "/api/fudan/volunteer/answer/save",
      [{ userId, examAnswer, examId }],
      token
    );
  }
  return Promise.resolve({
    data: {
      code: 0,
    },
  });
}

export function personalRank(token) {
  if (!MOCK) {
    return request("post", "/api/fudan/volunteer/answer/personRank", {}, token);
  }
  return Promise.resolve({
    data: {
      code: 0,
      rank: [
        {
          userId: "u1",
          username: "黎明",
          team_name: "无",
          score: 98,
        },
        {
          userId: "u2",
          username: "李虎",
          team_name: "无",
          score: 98,
        },
        {
          userId: "u3",
          username: "赵孟頫",
          team_name: "晋朝",
          score: 98,
        },
        {
          userId: "u4",
          username: "hummel",
          team_name: "无",
          score: 98,
        },
      ],
    },
  });
}

export function teamRank(token) {
  if (!MOCK) {
    return request("post", "/api/fudan/volunteer/answer/teamRank", {}, token);
  }
  return Promise.resolve({
    data: {
      code: 0,
      rank: [
        {
          teamId: "t1",
          team_name: "晋朝",
          score: 98,
        },
      ],
    },
  });
}
